def get_data_dict_from_file():
    with open('../data/新版标准日本语单词表.txt', 'r', encoding='utf-8')as f:
        # 分割每个课
        classes = f.read().split('\n\n')
        # print(classes)
        # print(len(classes))

        data_dict = {}
        for cls in classes:
            cls_dict = {}
            # 分割单词和句子
            word_lines, sentences_lines = cls.split('#')
            # print(word_lines, sentences)

            words = word_lines.strip().split('\n')
            # print(words[0])  # 第xx课  作为键

            sentences = sentences_lines.strip().split('\n')

            cls_dict['words'] = words[1:]
            cls_dict['sentence'] = sentences

            data_dict[words[0].strip()] = cls_dict
    # print(data_dict['第1课'])
    return data_dict


def get_words_from_word_list(word_list: list[str]):
    # -----找出类型有哪些-----
    # tp_lis = []

    for word in word_list:
        # -----找出格式不对的，手动修改-----
        # try:
        #     jps, tp, cns = word.split(' ')
        # except ValueError:
        #     print(f'at <<{word}>>')

        jps, tp, cns = word.split(' ')

        # print(jps, tp, cns)
        # tp_lis.append(tp)
    # print(set(tp_lis))  # {'〔动3〕', '〔副〕', '〔名〕', '〔动1〕', '〔专〕', '〔形1〕', '〔动2〕'}


if __name__ == '__main__':
    ddict = get_data_dict_from_file()
    for cls_num, word_list in ddict.items():
        get_words_from_word_list(word_list['words'])

